package com.open.capacity.prints.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.prints.entity.BillDgjsywsq;
import com.open.capacity.prints.service.BillDgjsywsqService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * 对公结算业务申请书
 *
 * @author 
 * @email 
 * @date 2021-04-07 09:40:45
 */
@RestController
@RequestMapping("dgjsywsq")
@Api(tags = "对公结算业务申请书")
public class BillDgjsywsqController {

    @Autowired
    private BillDgjsywsqService billDgjsywsqService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_dgjsywsq:billdgjsywsq:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billDgjsywsqService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询记录
     */
    @RequestMapping("/findBySqrFullname")
    @PreAuthorize("hasAnyAuthority('bill_dgjsywsq:billdgjsywsq:list')")
    public Result findBySqrFullname(String sqrFullname) {
        return Result.succeed(billDgjsywsqService.findBySqrFullname(sqrFullname));
    }
    /**
     * 查询记录
     */
    @RequestMapping("/findBySkrFullname")
    @PreAuthorize("hasAnyAuthority('bill_dgjsywsq:billdgjsywsq:list')")
    public Result findBySkrFullname(String skrFullname) {
        return Result.succeed(billDgjsywsqService.findBySkrFullname(skrFullname));
    }


    /**
    * 查询单条记录
    */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_dgjsywsq:billdgjsywsq:list')")
    public Result findById(String id) {
        return Result.succeed(billDgjsywsqService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_dgjsywsq:billdgjsywsq:save')")
    public Result save(@RequestBody @Valid BillDgjsywsq billDgjsywsq, String keyValue) {
    	 if(StringUtils.isEmpty(keyValue)) {
              keyValue = billDgjsywsqService.save(billDgjsywsq);
	     }else {
              billDgjsywsq.setId(keyValue);
              keyValue = billDgjsywsqService.update(billDgjsywsq);
	     }
        return Result.succeed(keyValue,"保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_ghyhjzd:billghyhjzd:delete')")
    public Result delete(@PathVariable String  id) {
            billDgjsywsqService.delete(id);
        return Result.succeed("删除成功");
    }

}
